﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using IllusionUtility.GetUtility;
using Manager;
using UnityEngine;

// Token: 0x020002E4 RID: 740
public class CameraControl_Ver2 : global::BaseCameraControl_Ver2
{
	// Token: 0x17000288 RID: 648
	// (get) Token: 0x06001222 RID: 4642 RVA: 0x00093EC4 File Offset: 0x000920C4
	// (set) Token: 0x06001223 RID: 4643 RVA: 0x00093ECC File Offset: 0x000920CC
	public bool isOutsideTargetTex { get; set; }

	// Token: 0x17000289 RID: 649
	// (get) Token: 0x06001224 RID: 4644 RVA: 0x00093ED8 File Offset: 0x000920D8
	// (set) Token: 0x06001225 RID: 4645 RVA: 0x00093EE0 File Offset: 0x000920E0
	public bool isCursorLock { get; set; }

	// Token: 0x1700028A RID: 650
	// (get) Token: 0x06001226 RID: 4646 RVA: 0x00093EEC File Offset: 0x000920EC
	// (set) Token: 0x06001227 RID: 4647 RVA: 0x00093EF4 File Offset: 0x000920F4
	public bool isConfigTargetTex { get; set; }

	// Token: 0x1700028B RID: 651
	// (get) Token: 0x06001228 RID: 4648 RVA: 0x00093F00 File Offset: 0x00092100
	// (set) Token: 0x06001229 RID: 4649 RVA: 0x00093F08 File Offset: 0x00092108
	public bool ConfigVanish
	{
		get
		{
			return this.isConfigVanish;
		}
		set
		{
			if (this.isConfigVanish != value)
			{
				this.isConfigVanish = value;
				this.visibleFroceVanish(true);
			}
		}
	}

	// Token: 0x1700028C RID: 652
	// (get) Token: 0x0600122A RID: 4650 RVA: 0x00093F24 File Offset: 0x00092124
	// (set) Token: 0x0600122B RID: 4651 RVA: 0x00093F2C File Offset: 0x0009212C
	public Transform targetTex { get; private set; }

	// Token: 0x0600122C RID: 4652 RVA: 0x00093F38 File Offset: 0x00092138
	public new virtual void Start()
	{
		base.Start();
		this.targetTex = base.transform.Find("CameraTarget");
		if (this.targetTex)
		{
			this.targetTex.localScale = Vector3.one * 0.01f;
			this.targetRender = this.targetTex.GetComponent<Renderer>();
		}
		this.isOutsideTargetTex = true;
		this.isConfigTargetTex = true;
		this.isConfigVanish = true;
		this.isCursorLock = true;
		this.viewCollider = base.gameObject.AddComponent<CapsuleCollider>();
		this.viewCollider.radius = 0.05f;
		this.viewCollider.isTrigger = true;
		this.viewCollider.direction = 2;
		Rigidbody rigidbody = base.gameObject.AddComponent<Rigidbody>();
		rigidbody.useGravity = false;
		rigidbody.isKinematic = true;
		this.isInit = true;
		this.listCollider.Clear();
	}

	// Token: 0x0600122D RID: 4653 RVA: 0x00094020 File Offset: 0x00092220
	public new virtual void LateUpdate()
	{
		/*if (global::Singleton<Manager.Scene>.Instance.NowSceneNames.Any((string s) => s == "Config" || s == "Check" || s == "HSceneClothChange" || s == "Shortcut" || s == "Config Trial"))
		{
			return;
		}
		if (!global::Singleton<Manager.Scene>.Instance.IsNowLoading && !global::Singleton<Manager.Scene>.Instance.IsNowLoadingFade)
		{
			base.LateUpdate();
		}*/
		if (this.targetTex)
		{
			if (this.transBase != null)
			{
				this.targetTex.position = this.transBase.TransformPoint(this.CamDat.Pos);
			}
			else
			{
				this.targetTex.position = this.CamDat.Pos;
			}
			Vector3 position = base.transform.position;
			position.y = this.targetTex.position.y;
			this.targetTex.transform.LookAt(position);
			this.targetTex.Rotate(new Vector3(90f, 0f, 0f));
			if (this.targetRender)
			{
				this.targetRender.enabled = (base.isControlNow & this.isOutsideTargetTex & this.isConfigTargetTex);
			}
			/*if (global::Singleton<global::GameCursor>.IsInstance() && this.isCursorLock)
			{
				global::Singleton<global::GameCursor>.Instance.SetCursorLock(base.isControlNow & this.isOutsideTargetTex);
			}*/
		}
		this.VanishProc();
	}

	// Token: 0x0600122E RID: 4654 RVA: 0x00094198 File Offset: 0x00092398
	public virtual void OnDisable()
	{
		this.visibleFroceVanish(true);
	}

	// Token: 0x0600122F RID: 4655 RVA: 0x000941A4 File Offset: 0x000923A4
	public virtual void OnTriggerEnter(Collider other)
	{
		Collider x2 = this.listCollider.Find((Collider x) => other.name == x.name);
		if (x2 == null)
		{
			this.listCollider.Add(other);
		}
	}

	// Token: 0x06001230 RID: 4656 RVA: 0x000941F4 File Offset: 0x000923F4
	public virtual void OnTriggerStay(Collider other)
	{
		Collider x2 = this.listCollider.Find((Collider x) => other.name == x.name);
		if (x2 == null)
		{
			this.listCollider.Add(other);
		}
	}

	// Token: 0x06001231 RID: 4657 RVA: 0x00094244 File Offset: 0x00092444
	public virtual void OnTriggerExit(Collider other)
	{
		this.listCollider.Clear();
	}

	// Token: 0x06001232 RID: 4658 RVA: 0x00094254 File Offset: 0x00092454
	public virtual void autoCamera(float _fSpeed)
	{
		this.CamDat.Rot.y = (this.CamDat.Rot.y + _fSpeed * Time.deltaTime) % 360f;
	}

	// Token: 0x06001233 RID: 4659 RVA: 0x00094284 File Offset: 0x00092484
	public virtual void CameraDataSave(string _strCreateAssetPath, string _strFile)
	{
		global::FileData fileData = new global::FileData(string.Empty);
		string text = fileData.Create(_strCreateAssetPath) + _strFile + ".txt";
		global::Debug.Log(text);
		using (StreamWriter streamWriter = new StreamWriter(text, false, Encoding.GetEncoding("UTF-8")))
		{
			streamWriter.Write(this.CamDat.Pos.x);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Pos.y);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Pos.z);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Dir.x);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Dir.y);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Dir.z);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Rot.x);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Rot.y);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Rot.z);
			streamWriter.Write('\n');
			streamWriter.Write(this.CamDat.Fov);
			streamWriter.Write('\n');
		}
	}

	// Token: 0x06001234 RID: 4660 RVA: 0x0009441C File Offset: 0x0009261C
	public virtual bool CameraDataLoad(string _assetbundleFolder, string _strFile, bool _isDirect = false)
	{
		string text = string.Empty;
		if (!_isDirect)
		{
			text = global::GlobalMethod.LoadAllListText(_assetbundleFolder, _strFile, null);
		}
		else
		{
			TextAsset textAsset = global::CommonLib.LoadAsset<TextAsset>(_assetbundleFolder, _strFile, false, string.Empty);
			global::AssetBundleManager.UnloadAssetBundle(_assetbundleFolder, true, null);
			if (textAsset)
			{
				text = textAsset.text;
			}
		}
		if (text == string.Empty)
		{
			global::GlobalMethod.DebugLog("cameraファイル読み込めません", 1);
			return false;
		}
		string[,] array;
		global::GlobalMethod.GetListString(text, out array);
		this.CamDat.Pos.x = float.Parse(array[0, 0]);
		this.CamDat.Pos.y = float.Parse(array[1, 0]);
		this.CamDat.Pos.z = float.Parse(array[2, 0]);
		this.CamDat.Dir.x = float.Parse(array[3, 0]);
		this.CamDat.Dir.y = float.Parse(array[4, 0]);
		this.CamDat.Dir.z = float.Parse(array[5, 0]);
		this.CamDat.Rot.x = float.Parse(array[6, 0]);
		this.CamDat.Rot.y = float.Parse(array[7, 0]);
		this.CamDat.Rot.z = float.Parse(array[8, 0]);
		this.CamDat.Fov = float.Parse(array[9, 0]);
		if (base.thisCmaera != null)
		{
			base.thisCmaera.fieldOfView = this.CamDat.Fov;
		}
		this.CamReset.Copy(this.CamDat, Quaternion.identity);
		base.CameraUpdate();
		if (!this.isInit)
		{
			this.isInit = true;
		}
		return true;
	}

	// Token: 0x06001235 RID: 4661 RVA: 0x00094604 File Offset: 0x00092804
	public virtual bool CameraResetDataLoad(string _assetbundleFolder, string _strFile, bool _isDirect = false)
	{
		string text = string.Empty;
		if (!_isDirect)
		{
			text = global::GlobalMethod.LoadAllListText(_assetbundleFolder, _strFile, null);
		}
		else
		{
			TextAsset textAsset = global::CommonLib.LoadAsset<TextAsset>(_assetbundleFolder, _strFile, false, string.Empty);
			global::AssetBundleManager.UnloadAssetBundle(_assetbundleFolder, true, null);
			if (textAsset)
			{
				text = textAsset.text;
			}
		}
		if (text == string.Empty)
		{
			global::GlobalMethod.DebugLog("cameraファイル読み込めません", 1);
			return false;
		}
		string[,] array;
		global::GlobalMethod.GetListString(text, out array);
		global::BaseCameraControl_Ver2.CameraData copy = default(global::BaseCameraControl_Ver2.CameraData);
		copy.Pos.x = float.Parse(array[0, 0]);
		copy.Pos.y = float.Parse(array[1, 0]);
		copy.Pos.z = float.Parse(array[2, 0]);
		copy.Dir.x = float.Parse(array[3, 0]);
		copy.Dir.y = float.Parse(array[4, 0]);
		copy.Dir.z = float.Parse(array[5, 0]);
		copy.Rot.x = float.Parse(array[6, 0]);
		copy.Rot.y = float.Parse(array[7, 0]);
		copy.Rot.z = float.Parse(array[8, 0]);
		copy.Fov = float.Parse(array[9, 0]);
		this.CamReset.Copy(copy, Quaternion.identity);
		return true;
	}

	// Token: 0x06001236 RID: 4662 RVA: 0x00094788 File Offset: 0x00092988
	public virtual bool loadVanish(string _assetbundleFolder, string _strMap, GameObject _objMap)
	{
		this.lstMapVanish.Clear();
		if (_objMap == null)
		{
			return false;
		}
		string text = global::GlobalMethod.LoadAllListText(_assetbundleFolder, _strMap, null);
		string[,] array;
		global::GlobalMethod.GetListString(text, out array);
		int length = array.GetLength(0);
		int length2 = array.GetLength(1);
		for (int i = 0; i < length; i++)
		{
			global::CameraControl_Ver2.VisibleObject visibleObject = new global::CameraControl_Ver2.VisibleObject();
			visibleObject.nameCollider = array[i, 0];
			for (int j = 1; j < length2; j++)
			{
				string text2 = array[i, j];
				if (text2 == string.Empty)
				{
					break;
				}
				GameObject gameObject = _objMap.transform.FindLoop(text2);
				if (!(gameObject == null))
				{
					visibleObject.listObj.Add(gameObject);
				}
			}
			this.lstMapVanish.Add(visibleObject);
		}
		return true;
	}

	// Token: 0x06001237 RID: 4663 RVA: 0x00094874 File Offset: 0x00092A74
	public virtual void visibleFroceVanish(bool _visible)
	{
		foreach (global::CameraControl_Ver2.VisibleObject visibleObject in this.lstMapVanish)
		{
			foreach (GameObject gameObject in visibleObject.listObj)
			{
				if (gameObject)
				{
					gameObject.SetActive(_visible);
				}
			}
			visibleObject.isVisible = _visible;
			visibleObject.delay = ((!_visible) ? 0f : 0.3f);
		}
	}

	// Token: 0x06001238 RID: 4664 RVA: 0x00094940 File Offset: 0x00092B40
	public virtual void visibleFroceVanish(global::CameraControl_Ver2.VisibleObject _obj, bool _visible)
	{
		if (_obj == null)
		{
			return;
		}
		if (_obj.listObj == null)
		{
			return;
		}
		for (int i = 0; i < _obj.listObj.Count; i++)
		{
			_obj.listObj[i].SetActive(_visible);
		}
		_obj.delay = ((!_visible) ? 0f : 0.3f);
		_obj.isVisible = _visible;
	}

	// Token: 0x06001239 RID: 4665 RVA: 0x000949B0 File Offset: 0x00092BB0
	public virtual bool VanishProc()
	{
		if (!this.isConfigVanish)
		{
			return false;
		}
		int i;
		for (i = 0; i < this.lstMapVanish.Count; i++)
		{
			Collider x2 = this.listCollider.Find((Collider x) => this.lstMapVanish[i].nameCollider == x.name);
			if (x2 == null)
			{
				this.VanishDelayVisible(this.lstMapVanish[i]);
			}
			else if (this.lstMapVanish[i].isVisible)
			{
				this.visibleFroceVanish(this.lstMapVanish[i], false);
			}
		}
		return true;
	}

	// Token: 0x0600123A RID: 4666 RVA: 0x00094A84 File Offset: 0x00092C84
	public virtual bool VanishDelayVisible(global::CameraControl_Ver2.VisibleObject _visible)
	{
		if (_visible.isVisible)
		{
			return false;
		}
		_visible.delay += Time.deltaTime;
		if (_visible.delay >= 0.3f)
		{
			this.visibleFroceVanish(_visible, true);
		}
		return true;
	}

	// Token: 0x0400181B RID: 6171
	protected bool isConfigVanish = true;

	// Token: 0x0400181C RID: 6172
	protected Renderer targetRender;

	// Token: 0x0400181D RID: 6173
	protected List<global::CameraControl_Ver2.VisibleObject> lstMapVanish = new List<global::CameraControl_Ver2.VisibleObject>();

	// Token: 0x0400181E RID: 6174
	protected List<Collider> listCollider = new List<Collider>();

	// Token: 0x020002E5 RID: 741
	public class VisibleObject
	{
		// Token: 0x04001824 RID: 6180
		public string nameCollider;

		// Token: 0x04001825 RID: 6181
		public float delay;

		// Token: 0x04001826 RID: 6182
		public bool isVisible = true;

		// Token: 0x04001827 RID: 6183
		public List<GameObject> listObj = new List<GameObject>();
	}
}
